package com.wh1200.mybatis.xmlless

import cn.hutool.core.util.ReflectUtil
import com.wh1200.mybatis.xmlless.config.BaseResolverTest
import com.wh1200.mybatis.xmlless.constant.ClassNames
import com.wh1200.mybatis.xmlless.util.ClassUtils.getAllClassOrInterface
import com.wh1200.xmlless.test.dao.UserDAO
import com.wh1200.xmlless.test.model.User
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import kotlin.test.assertContains

/**
 *
 * @author wuhao
 * @date 2024/1/16 14:52
 * @since v0.0.0
 * @version 1.0
 */
class ClassUtilTest : BaseResolverTest(
    UserDAO::class.java
) {

  @Test
  @DisplayName("测试mybatis-plus的字段解析不包含带有@Count注解的字段")
  fun test() {
    val clazz = User::class.java
    val fields = TableInfoHelper.getAllFields(clazz)
    val fields2 = ReflectUtil.getFields(clazz)
    val fields3 = fields2.filter { it !in fields }
    assert(fields3.isNotEmpty())
  }

  @Test
  @DisplayName("测试获取所有父类以及继承的接口")
  fun getAllSuperClassesAndInterfaces() {
    val type = A::class.java
    val list = getAllClassOrInterface(type)
    assertContains(list.map { it.name }, ClassNames.JAVA_COLLECTION)
  }

  class A : B(1) {
  }

  open class B(override val size: Int) : Collection<String> {

    override fun contains(element: String): Boolean {
      TODO("Not yet implemented")
    }

    override fun containsAll(elements: Collection<String>): Boolean {
      TODO("Not yet implemented")
    }

    override fun isEmpty(): Boolean {
      TODO("Not yet implemented")
    }

    override fun iterator(): Iterator<String> {
      TODO("Not yet implemented")
    }

  }

}
